import expedia.HotelAddress;
import expedia.HotelInfoResponse;
import expedia.HotelInformationResponseExpedia;
import org.apache.commons.lang3.StringUtils;
import service.ExpediaHttpService;
import service.ExpediaHttpServiceImpl;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @description: ean新酒店映射id找不到核查
 * @author: yuanjianpeng5
 * @createdate: 2020-03-02 09:52
 * @lastdate:
 */
public class EanHotelIdNotFoundVerify {

    public static void main(String[] args) throws IOException {
        ExpediaHttpService expediaHttpService = new ExpediaHttpServiceImpl();
        String path = new SimpleDateFormat("yyyy_MM_dd_hh_mm_ss").format(new Date());
        String realPath = ScoreTest.class.getClassLoader().getResource("").getFile();
        File fin = new File(realPath + "invaldHotelCodeList");
        File fou = new File(realPath + "checkedinvaldHotelCodeListList" + path +".txt");
        FileInputStream fis = new FileInputStream(fin);
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fis, "UTF-8"));
        OutputStream out = new FileOutputStream(fou);
        OutputStreamWriter writer = new OutputStreamWriter(out, "UTF-8");
        int count = 0;
        String line = null; // 第一行是标头 不要
        for (line = bufferedReader.readLine(); line != null && count < 1100; line = bufferedReader.readLine()) {
            Map<String, String> option = new HashMap<>();
            option.put("include", "address");
            HotelInfoResponse result = expediaHttpService.getHotelInfoCN(line, option, null);
            if (null == result || !StringUtils.isEmpty(result.getType())) { //正常取得返回值时作处理
                writer.append("Ean无该酒店").append("\t").append(line).append("\n");
            } else {
                Map<String, HotelInformationResponseExpedia> resultRegionInfo = result.getHotelInformationResponse();
                for (Map.Entry<String, HotelInformationResponseExpedia> entry : resultRegionInfo.entrySet()) {
                    HotelAddress hotelAddress = entry.getValue().getHotelAddress();
                    if (null == hotelAddress || "CN".equals(hotelAddress.getCountryCode())) {
                        writer.append("该酒店所属国家不明确或是国内").append("\t").append(line).append("\n");
                    } else {
                        writer.append("成功找到该国际酒店").append("\t").append(line).append("\n");
                    }
                }
            }
            count++;
        }
        System.out.println("共处理数目" + count);
        writer.close();
        out.close();
        bufferedReader.close();
        fis.close();
    }
}